home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
-
- /* A utility routine called by NameFileSearch and CreatorTypeFileSearch to
- ** allocate a optimization buffer. */
-
- static Ptr GetSearchBuffer(long *buffSize);
- static Ptr GetSearchBuffer(long *buffSize)
- {
- Ptr tempPtr;
-
- *buffSize = 0x00004000; /* start by trying for a 16K buffer */
- while ( *buffSize != 0 ) /* and keep trying until *buffSize is zero */
- {
- tempPtr = NewPtr(*buffSize);
- if ( tempPtr != NULL )
- break; /* got it */
- else
- *buffSize -= 0x00000400; /* didn't get it, subtract 1K and try again */
- }
- return ( tempPtr );
- }
-
- /*****************************************************************************/
-
- pascal OSErr IndexedSearch(CSParamPtr pb, long dirID);
-
- pascal OSErr FindEverything(short vRefNum,
- long dirID,
- FSSpecPtr matches,
- long reqMatchCount,
- long *actMatchCount,
- Boolean newSearch);
- pascal OSErr FindEverything(short vRefNum,
- long dirID,
- FSSpecPtr matches,
- long reqMatchCount,
- long *actMatchCount,
- Boolean newSearch)
- {
- CInfoPBRec searchInfo1, searchInfo2;
- HParamBlockRec pb;
- OSErr error;
- static CatPositionRec catPosition;
-
- pb.csParam.ioNamePtr = NULL;
- pb.csParam.ioVRefNum = vRefNum;
- pb.csParam.ioMatchPtr = matches;
- pb.csParam.ioReqMatchCount = reqMatchCount;
- pb.csParam.ioSearchBits = 0; /* find all matches */
- pb.csParam.ioSearchInfo1 = &searchInfo1;
- pb.csParam.ioSearchInfo2 = &searchInfo2;
- pb.csParam.ioSearchTime = 0;
- if ( newSearch )
- {
- catPosition.initialize = 0; /* then search from beginning of catalog */
- }
- pb.csParam.ioCatPosition = catPosition;
- pb.csParam.ioOptBuffer = GetSearchBuffer(&pb.csParam.ioOptBufSize);
-
- if ( dirID == fsRtDirID )
- {
- error = PBCatSearchSync((CSParamPtr)&pb);
- }
- else
- {
- error = IndexedSearch((CSParamPtr)&pb, dirID);
- }
-
- if ( (error == noErr) || /* If no errors or the end of catalog was */
- (error == eofErr) ) /* found, then the call was successful so */
- {
- *actMatchCount = pb.csParam.ioActMatchCount; /* return the match count */
- }
- else
- {
- *actMatchCount = 0; /* else no matches found */
- }
-
- if ( (error == noErr) || /* If no errors */
- (error == catChangedErr) ) /* or there was a change in the catalog */
- {
- catPosition = pb.csParam.ioCatPosition;
- /* we can probably start the next search where we stopped this time */
- }
- else
- {
- catPosition.initialize = 0;
- /* start the next search from beginning of catalog */
- }
-
- if ( pb.csParam.ioOptBuffer != NULL )
- {
- DisposPtr(pb.csParam.ioOptBuffer);
- }
-
- return ( error );
- }
-
-